package com.grm.datasource.mapper;

import com.grm.datasource.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    /**
     * 新增用户
     * @param user
     * @return
     */
    @Insert("insert into user (username,`password`,sex,age) values (#{username},#{password},#{sex},#{age})")
    int save(User user);

    /**
     * 更新用户信息
     * @param user
     * @return
     */
    @Update("update user set username = #{username} where id = #{id}")
    int update(User user);

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @Delete("delete from user where id =#{id}")
    int deleteById(Long id);

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Select("select * from user where id = #{id}")
    User selectById(Long id);

    /**
     * 查询所有用户信息
     * @return
     */
    @Select("select * from user")
    List<User> selectAll();
}
